﻿function memberCheck(id) {
    var arr_ext = ["One", "Three", "Four", "Five"];//var arr_ext = ["One", "Two", "Three", "Four", "Five"];
    for (i = 0; i < arr_ext.length; i++) {
        var lb_id = "label" + arr_ext[i];
        var ipt_id = "membership" + arr_ext[i];
        if (lb_id == id || ipt_id == id) {
            document.getElementById(lb_id).style.color = '#ffff00';
            document.getElementById(ipt_id).checked = true;
        } else {
            document.getElementById(lb_id).style.color = '#dddddd';
            document.getElementById(ipt_id).checked = false;
        }
    }
}
function registerCheck(f) {
    var ret = true;
    var alert_msg = '';
    if ((f.usernameReg.value.search(/[^A-Z0-9_]/i) !== -1) || f.usernameReg.value == '') {
        alert_msg += "*Username can only contain letters, numbers and underscores(_)!\r\n";
        ret = false;
    }
    if (f.passwordReg.value.length <= 5) {
        alert_msg += "*Password must have at least 6 characters\r\n";
        ret = false;
    } else if (f.passwordReg.value != f.passwordAgn.value) {
        alert_msg += "*Your passwords don't match!\r\n";
        ret = false;
    }
    if (!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(f.emailText.value)) {
        alert_msg += "*You have input invalid email address!\r\n";
        ret = false;
    }
    if (f.birthYear.value == 'Example: 1990' || (!/^\d{4}$/.test(f.birthYear.value))) {
        alert_msg += "*Please input valid birth year! Example: 1990\r\n";
        ret = false;
    }
    var arr_ms = f.membership;
    var is_m = false;
    for (var i = 0; i < arr_ms.length; i++) {
        if (arr_ms[i].checked && arr_ms[i].value) {
            is_m = true;
        }
    }
    if (!is_m) {
        alert_msg += "*Please choose your membership!\r\n";
        ret = false;
    }
    if (!ret) {
        alert(alert_msg);
    }
    return ret;

}
function changePwd(f) {
    var ret = true;
    var alert_msg = '';
    if (f.passwordold.value.length <= 5) {
        ret = false;
        alert_msg += "*Please input valid old password!\r\n";
    }
    if (f.passwordnew.value.length <= 5) {
        ret = false;
        alert_msg += "*New password must have at least 6 characters!\r\n";
    } else if (f.passwordnew.value != f.passwordnewagn.value) {
        ret = false;
        alert_msg += "*Your new passwords don't match!";
    }
    if (!ret) {
        alert(alert_msg);
    }
    return ret;
}
function changeEmail(f) {
    var ret = true;
    var alert_msg = '';
    if (!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(f.email.value)) {
        alert_msg += "*You have input invalid email address!";
        ret = false;
    }
    if (!ret) {
        alert(alert_msg);
    }
    return ret;
}
function topupItem(id) {
    //		var arr_ext = ["Two", "Three", "Four", "Five"];
    var arr_ext = ["Three", "Four", "Five"];
    for (i = 0; i < arr_ext.length; i++) {
        var lb_id = "label" + arr_ext[i];
        var ipt_id = "membership" + arr_ext[i];
        if (lb_id == id || ipt_id == id) {
            document.getElementById(lb_id).style.color = '#ffff00';
            document.getElementById(ipt_id).checked = true;
        } else {
            document.getElementById(lb_id).style.color = '#bbbbbb';
            document.getElementById(ipt_id).checked = false;
        }
    }
}
function checkTopup(f) {
    var ret = true;
    var alert_msg = '';
    var arr_ms = f.membership;
    var is_m = false;
    for (var i = 0; i < arr_ms.length; i++) {
        if (arr_ms[i].checked && arr_ms[i].value) {
            is_m = true;
        }
    }
    if (!is_m) {
        alert_msg = "* Please choose your top-up plan!\r\n";
        ret = false;
        alert(alert_msg);
    }
    return ret;
}
function contactCheck(f) {
    var ret = true;
    var alert_msg = '';
    if (f.contactname.value == '') {
        alert_msg += "* Please input your name!\r\n";
        ret = false;
    }
    if (!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(f.emailtext.value)) {
        alert_msg += "* You have input invalid email address!\r\n";
        ret = false;
    }
    if (f.subjecttext.value == '') {
        alert_msg += "* Please input subject!\r\n";
        ret = false;
    }
    if (f.contactarea.value.length <= 9) {
        alert_msg += "* Message must have at least 10 characters!\r\n";
        ret = false;
    }
    if (!ret) {
        alert(alert_msg);
    }
    return ret;
}